[php] how to read only 5 last line of the txt file

Posted by safaali on Stack Overflow See other posts from Stack Overflow or by safaali
Published on 2010-06-02T21:09:18Z Indexed on 2010/06/02 21:14 UTC
Read the original article Hit count: 123

Filed under:
|

hello

i have a file named "file.txt" it updates by adding lines to it.

I am reading it by this code:

$fp = fopen("file.txt", "r");
$data = "";
while(!feof($fp))
{
$data .= fgets($fp, 4096);
}
echo $data;

and a huge number of lines appears. I just want to echo the last 5 lines of the file

how can i do that ?

thanks in advanced

© Stack Overflow or respective owner

Related posts about php

Related posts about fopen